<template>
  <div>
    <!-- 给车队派单 2018/6/12 zhangQ -->
    <Row :style="{minHeight:350+'px'}">
      <i-col span="20">
        <Form ref="sendNoticeForm" :model="sendNoticeForm" label-position="left" :label-width="100" :rules="sendNoticeFormRules">
          <!--<template v-for="(item, index) in trackName">
            <FormItem :label="item.login_name">
              <Select v-model="sendNoticeForm.data[index].address" filterable multiple :value="sendNoticeForm.data[index].address" style="width: 400px">
                <template v-for="(addressItem, index) in address">
                  <Option :value="addressItem" :key="index">{{addressItem}}</Option>
                </template>
              </Select>
            </FormItem>
          </template>-->
          <!--{{ sendNoticeForm.checkTrackName | json }}-->
          <FormItem label="选择车队：">
            <CheckboxGroup v-model="sendNoticeForm.checkTrackName">
              <template v-for="(item, index) in trackName">
                <Checkbox :label="item.id">
                  <span>{{ item.login_name}}</span>
                </Checkbox>
              </template>
            </CheckboxGroup>
          </FormItem>
          <FormItem label="对位股道" prop="paraPositionTrack">
            <Select v-model="sendNoticeForm.paraPositionTrack">
              <Option v-for="item in trackOptions" :value="item" :key="item">
                {{item}}
              </Option>
            </Select>
          </FormItem>
          <FormItem label="预计到达时间" prop="estimateArriveTime">
            <DatePicker type="datetime" placeholder="选择需求时间" v-model="sendNoticeForm.estimateArriveTime" style="width: 200px"></DatePicker>
          </FormItem>
          <FormItem label="收货地址：" prop="address">
            <Input v-model="sendNoticeForm.address"></Input>
          </FormItem>
          <FormItem label="公里数：" prop="address">
            <Input v-model="sendNoticeForm.kilometreNumber" type="number"></Input>
          </FormItem>

          <FormItem label="联系人：" prop="contacts">
            <Input v-model="sendNoticeForm.contacts"></Input>
          </FormItem>
          <FormItem label="联系电话：" prop="contactsMobile">
            <Input v-model="sendNoticeForm.contactsMobile"></Input>
          </FormItem>

        </Form>
      </i-col>
    </Row>
    <div class="xlinkModal-footer">
      <Button type="primary" @click="sendNoticeToFleet">确认发送</Button>
      <Button @click="cancel">取消</Button>
    </div>
  </div>
</template>

<script>
  import {getTrackList, getOwnFleet, getAddressList} from '@api/backEnd/station'
  import moment from 'moment'

  export default {
    name: 'dispatchToFleet',
    data () {
      let sendNoticeFormRules = {}
      let sendNoticeForm = {
        checkTrackName: [],
        address: '',
        contacts: '', // 联系人
        contactsMobile: '', // 联系电话
        kilometreNumber: '', // 公里数
        mainOrderNo: '',
        paraPositionTrack: '',
        estimateArriveTime: '',
        data: []
      }
      let trackOptions = []
      let trackName = []
      let address = []
      let checkTrackName = []
      let datas = {sendNoticeForm, trackOptions, trackName, address, checkTrackName, sendNoticeFormRules}
      return datas
    },
    computed: {},
    methods: {
      cancel () {
        this.$emit('close')
      },
      sendNoticeToFleet () {
        // console.log(this.sendNoticeForm)
        // if (!this.sendNoticeForm.address) {
        //   this.$Notice.warning({
        //     title: '错误',
        //     desc: '送货地址必填'
        //   })
        //   return
        // }
        let mobileReg = /^((0\d{2,3}-\d{7,8})|(1[35847]\d{9}))$/
        if (this.sendNoticeForm.contactsMobile && !mobileReg.test(this.sendNoticeForm.contactsMobile)) {
          this.$Notice.warning({
            title: '错误',
            desc: '手机号码不正确！'
          })
          return
        }
        let contactsReg = /^[\u4e00-\u9fa5].*$/
        if (this.sendNoticeForm.contacts && !contactsReg.test(this.sendNoticeForm.contacts)) {
          this.$Notice.warning({
            title: '错误',
            desc: '联系人首字母必须为汉字！'
          })
          return
        }
        // if (!this.sendNoticeForm.estimateArriveTime) {
        //   this.$Notice.warning({
        //     title: '错误',
        //     desc: '预计到达时间必填！'
        //   })
        //   return
        // }
        // 开始发货
        this.sendNoticeForm.estimateArriveTime = this.sendNoticeForm.estimateArriveTime ? moment(this.sendNoticeForm.estimateArriveTime).format('YYYY-MM-DD HH:mm:ss') : ''
        this.$emit('assignment', this.sendNoticeForm)
      },
      getData () {
        getTrackList().then(res => {
          if (res.data.isSuccess === 1) {
            this.trackOptions = res.data.data
          }
        })
        getOwnFleet().then(res => {
          if (res.data.isSuccess === 1) {
            this.trackName = res.data.data
            this.newObj = this.trackName
            for (let i = 0; i < this.newObj.length; i++) {
              this.sendNoticeForm.data.push({
                truckName: this.newObj[i].login_name,
                address: []
              })
            }
          }
        })
        getAddressList().then(res => {
          if (res.data.isSuccess === 1) {
            this.address = res.data.data
          }
        })
      }
    },
    created () {
    },
    mounted () {
      this.getData()
    },
    components: {}
  }
</script>

<style scoped>

</style>
